﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace PlayDeezGames.Common
{
    public abstract class State<StateId>:MessageHandlerBase 
    {
        protected void Start()
        {
            ExitState = default(StateId);
            Finished = false;
            OnStart();
        }
        protected void Idle()
        {
            if (!Finished)
            {
                OnIdle();
            }
        }
        protected void Finish()
        {
            if (!Finished)
            {
                Finished = true;
                OnFinish();
            }
        }
        protected abstract void OnStart();
        protected abstract void OnIdle();
        protected abstract void OnFinish();
        public StateId ExitState { get; protected set; }
        public bool Finished { get; protected set; }
        public State():base(null)
        {
            Finished = true;
            ExitState = default(StateId);
        }
        public override bool OnMessage(MessageBase theMessage)
        {
            if (theMessage.MessageId == MSGID_StartState)
            {
                Start();
                return true;
            }
            else if (theMessage.MessageId == MSGID_IdleState)
            {
                Idle();
                return true;
            }
            else if (theMessage.MessageId == MSGID_FinishState)
            {
                Finish();
                return true;
            }
            else
            {
                return base.OnMessage(theMessage);
            }
        }

        public static void MSGID_StartState() { }
        public static void MSGID_IdleState() { }
        public static void MSGID_FinishState() { }
    }
}
